package controller;

import javax.swing.JList;
import javax.swing.JProgressBar;
import javax.swing.JTextPane;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import model.BinForm;
import model.BinSetVariables;
import model.FileList;
/**
 * 
 * @author Estelle && Marie
 *
 *This function is to implement the action list listener of our list.
 *When the user clic on a element of the list, the contents of the formulary is set with the contents of the list
 *
 */

public class ActionList implements ListSelectionListener{

	private JTextPane center;
	private BinForm bin;
	private JList simulation;
	private JProgressBar bar;
	
	public ActionList(JList simulation, JTextPane center, BinForm bin,JProgressBar bar){
		this.simulation = simulation;
		this.center = center;
		this.bin = bin;
		this.bar = bar;
	}
	
	
	@Override
	public void valueChanged(ListSelectionEvent arg0) {
		// TODO Auto-generated method stub
		// we take the element selected by the user and storage it in a string
		 String name = simulation.getSelectedValue().toString() + ".txt";
		 
		//we create an object of the filelist to get the contents of the list
		 FileList file = new FileList();
		 BinSetVariables variables;
		 
		 if(!name.equals(null)){
			 center.setText("\t Start the :" + name );
			 variables = file.readFile(simulation.getSelectedValue().toString(),center);
			 bin.resetTextForm(variables);
		 }
		 else{
			 center.setText("Error in controller.ActionList l 42 : name of file is empty");
		 }
		
	}

}
